<template>
	<view>
        <u-popup :show="show" mode="bottom" :round="10" @close="closeShow" >
            <div class="popupTitle">确认价格</div>
        	<div class="popup-con">
        		<u--form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth="100" errorType="toast">
        			<u-form-item  label="销售还价" borderBottom>
        				<div style="text-align: right;">{{form.reducePrice}}</div>
        			</u-form-item>
        			<u-form-item  borderBottom  prop="finalPrice" labelWidth="0">
						<div  slot="default" style="width:100%">
							<div style="width:400rpx;float:left"><span style="color:#f56c6c;padding-right:10rpx">*</span>确认价格(含佣金{{serviceChargeRatio | fifterNum(form.finalPrice,serviceType)}})</div>
							<div style="width:calc(100% - 400rpx);float:right;">
								<u--input v-model="form.finalPrice"   placeholder="请输入确认价格" border="none" inputAlign="right"></u--input>
							</div>
						</div>
        				
						
        			</u-form-item>
        		</u--form>
        	</div>
        	<div class="u-flex popup-bottom">
        		<u-button text="取消"  shape="circle" @click="closeShow"></u-button>
        		<u-button text="确认"  shape="circle" type="primary" @click="saveForm" :loading="btnLoading"></u-button>
        	</div>
        </u-popup>
	</view>
</template>
<script>


import {priceOperate} from '@/config/api2.js'
import store from '@/store';

const defaultForm={
		     operateType : "", 
			 priceId:'',
			 finalPrice:'',
			 reducePrice:'',
	    }
export default {
    name: 'comfirmPrice',
    computed: {
    	
		
    },
	data() {
		return {
          form:JSON.parse(JSON.stringify(defaultForm)),
          show:false,
          rules: {
          	finalPrice: [{
          			required: true,
          			message: '请输入确认价格',
          			// 可以单个或者同时写两个触发验证方式
          			trigger: ['blur', 'change']
          		}],
          },
		 btnLoading:false,
		 serviceChargeRatio:'',
		 serviceType:''
		}
	},
    watch:{

    },
	created() {
	
	},
	filters:{
		fifterNum(val,price,type){
			if(type == 0){
				if(parseFloat(val)*1000){
					return (parseFloat(val)*1*1000).toFixed(2)
				}else{
					return 0.00
				}
			}else if(type == 1){
				if(parseFloat(val)*1*parseFloat(price)){
					return (parseFloat(val)*1*parseFloat(price)).toFixed(2)
				}else{
					return 0.00
				}
			}	
		}
    },
	methods: {
		init(item,serviceChargeRatio,serviceType){
			console.log("item",item)
			this.show = true;
			this.form = JSON.parse(JSON.stringify(defaultForm));
			this.form.operateType = 'confirm';
			this.form.priceId = item.priceId;
			this.form.finalPrice = item.reducePrice;
			this.form.reducePrice = item.reducePrice;
			this.serviceType = serviceType;
			this.serviceChargeRatio = serviceChargeRatio;
			setTimeout(()=>{
				console.log("$refs",this.$refs)
				// #ifdef MP	
					this.$refs.form.setRules(this.rules)
				// #endif
				
			},1000)	
		},
		closeShow(){
			this.show = false
		},
		
		saveForm(){
		  // console.log("this.$refs.form",this.$refs.form)
		  this.$refs.form.validate().then(res => {
			   this.btnLoading = true;
			   let  data = JSON.parse(JSON.stringify(this.form));
				 priceOperate(data).then(()=>{
					   this.btnLoading = false;
					   this.show = false
					   this.$emit('refresh')
				 }).catch(()=>{
					   this.btnLoading = false;
				 })
			  }).catch(errors => {
				
			  })
		},
        
	}
};
</script>

<style lang="scss" scoped>
@import '@/style/common.scss';
.popupTitle{
	font-size:$b-font;
	font-weight: bold;
	text-align: center;
	line-height: 50px;
}
   .popup-con{
    	padding:0 16px 16px 16px;
    	.popup-block-pay{
    		text-align: center;
    		padding:20px;
    		.price-sub-title{
    			font-size:$s-font;
    			color:$g-font-color;
    			line-height: 30px;
    		}
    		.price-big-title{
    			font-size: 22px;
    			color:$theme-color;
    			font-weight:bold;
    			margin-top:10px;
    		}
    	}
    	.popup-label{
    		line-height: 40px;
    		font-size:$m-font;
    		color:$g-font-color;
    		@include flexbox(space-between,center)
    	}
    	.img-div{
    		width:210px;
    		height:210px;
    		border:1px solid $border-color;
    		margin:0 auto;
    		background: #f4f5f7;
    	}
        .send-list{
    		padding-top:$marginSpace;
    		.send-item{
    			border-radius: 8px;
    			padding:12px;
    			box-shadow: 0 0 5px rgba(0,0,0,0.1);
    			margin-bottom:$marginSpace;
    			.send-top{
    				@include flexbox(flex-start,flex-start);
    				font-size:$m-font;
    				.name{
    					padding-right:12px;
    					flex:1
    				}
    				.num{
    					font-weight: bold;
    					color:$theme-color
    				}
    			}
    			.send-middle{
    				font-size:$s-font;
    				color:$g-font-color;
    				line-height: 18px;
    				margin-top:5px;
    			}
    			.send-bottom{
    				text-align: right;
    				font-size:$s-font;
    				margin-top:16px
    			}
    		}
    	}
    	.category-list{
    		padding:36rpx 0;
    		.list-item{
    			@include flexbox(flex-start,flex-start);
    			margin-bottom:20rpx;
    			.item-title{
    				width: 126rpx;
    				height: 52rpx;
    				background: rgba(255,255,255,0.39);
    				border: 1px solid #B8B8B8;
    				border-radius: 9rpx;
    				font-size:$m-font;
    				text-align: center;
    				line-height: 52rpx;
    			}
    			.item-list{
    				padding-left:30rpx;
    				width:calc(100% - 126rpx);
    				overflow: hidden;
    				.item-ename{
    					font-size:$s-font;
    					color: #929292;
    					line-height: 52rpx;
    					width: 170rpx;
    					@include textoverflow(1);
    					float:left;
    				}
    			}
    		}
    	}
    	.goodsSn-list{
    		border: 1px solid #DEDEDE;
    		padding:0 10px;
    		font-size:$s-font;
    		margin-top:15px;
    		padding-bottom:10px;
    		.list-cell{
    			border-bottom:1px solid #DEDEDE;
    			@include flexbox(space-between,center);
    			line-height: 60rpx;
    			height:60rpx;
    		}
    		.list-cell:first-child{
    			
    		}
    	}
    	.audio-text{
    		font-size: 34rpx;
    		line-height: 48rpx;
    		color: #414141;
    		text-align: center;
    		padding-top:100rpx;
    	}
    	.audio-dh{
    		@include flexbox(space-between,center);
    	}
    
    }
    .popup-bottom{
    	background: #fff;
    	margin-top:10px;
    	padding:16px;
    }
    .popup-bottom-fixed{
    	position: fixed;
    	width:100%;
    	padding:16px;
    	box-sizing: border-box;
    	bottom:0
    }
    
    

</style>
